package net.stuffrepos.bricknetcenter.util;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Eduardo H. Bogoni <eduardobogoni@gmail.com>
 */
public class HierarchicalProperties {

    private Map values = new HashMap();
    private Map<Object, Boolean> setted = new HashMap<Object, Boolean>();
    private HierarchicalProperties parent;

    public HierarchicalProperties() {
        this(null);
    }

    public HierarchicalProperties(HierarchicalProperties parent) {
        this.parent = parent;
    }

    public Object getValue(Object key) {
        if (setted.get(key) != null && setted.get(key)) {
            return values.get(key);
        } else if (parent != null) {
            return parent.getValue(key);
        } else {
            return null;
        }
    }

    public int getIntegerValue(Object key) {
        return ((Number) getValue(key)).intValue();
    }

    public double getDoubleValue(Object key) {
        return ((Number) getValue(key)).doubleValue();
    }

    public HierarchicalProperties setValue(Object key, Object value) {
        values.put(key, value);
        setted.put(key, true);
        return this;
    }

    public HierarchicalProperties unsetValue(Object key) {
        setted.put(key, false);
        return this;
    }
}
